//
//  GDeviceManager.m
//  ClassManager
//
//  Created by ihope99 on 2017/8/16.
//  Copyright © 2017年 GZX. All rights reserved.
//

#import "GDeviceManager.h"



void EMSystemSoundFinishedPlayingCallback(SystemSoundID sound_id, void* user_data)
{
    AudioServicesDisposeSystemSoundID(sound_id);
}

@implementation GDeviceManager


// The system sound for a new message
+(SystemSoundID)playNewMessageSoundWithPath:(NSString *)path
{
    // Path for the audio file
    NSURL *bundlePath = [[NSBundle mainBundle] URLForResource:path withExtension:nil];
    
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)(bundlePath), &soundID);
    // Register the sound completion callback.
    AudioServicesAddSystemSoundCompletion(soundID,
                                          NULL, // uses the main run loop
                                          NULL, // uses kCFRunLoopDefaultMode
                                          EMSystemSoundFinishedPlayingCallback, // the name of our custom callback function
                                          NULL // for user data, but we don't need to do that in this case, so we just pass NULL
                                          );
    
    AudioServicesPlaySystemSound(soundID);
    
    return soundID;
}

+(void)playVibration
{
    // Register the sound completion callback.
    AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate,
                                          NULL, // uses the main run loop
                                          NULL, // uses kCFRunLoopDefaultMode
                                          EMSystemSoundFinishedPlayingCallback, // the name of our custom callback function
                                          NULL // for user data, but we don't need to do that in this case, so we just pass NULL
                                          );
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}


@end
